package com.css.fxfzfxqh.modules.lifelineEngineering.controller;

import com.css.fxfzfxqh.base.response.RestResponse;
import com.css.fxfzfxqh.common.rest.model.param.YsxDataSourcePageParam;
import com.css.fxfzfxqh.modules.lifelineEngineering.param.PageParam;
import com.css.fxfzfxqh.modules.lifelineEngineering.service.LifelineDataService;
import com.css.fxfzfxqh.util.PlatformPageUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * 数据源
 */
@RestController
@RequestMapping("lifelineData")
@Slf4j
public class LifelineDataController {

    @Autowired
    private LifelineDataService lifelineDataService;

    /**
     * 生命线工程数据源查询
     */
    @GetMapping("page")
    public RestResponse page(HttpServletRequest request, YsxDataSourcePageParam param){
        try {
            int page = Integer.parseInt(request.getParameter(PlatformPageUtils.CUR_PAGE));
            int size = Integer.parseInt(request.getParameter(PlatformPageUtils.PAGE_SIZE));
            param.setPage(page);
            param.setRows(size);
            Map<String, Object> data = lifelineDataService.page(param);
            return RestResponse.succeed(data);
        } catch (Exception e) {
            log.error("get page error:{}",e.getMessage(),e);
            return RestResponse.fail("查询失败!");
        }
    }

    /**
     * 地震影响场数据源查询
     */
    @GetMapping("influenceField")
    public RestResponse influenceField(HttpServletRequest request, PageParam param){
        try {
            int page = Integer.parseInt(request.getParameter(PlatformPageUtils.CUR_PAGE));
            int size = Integer.parseInt(request.getParameter(PlatformPageUtils.PAGE_SIZE));
            Map<String, Object> data = lifelineDataService.influenceField(param, page, size);
            return RestResponse.succeed(data);
        } catch (Exception e) {
            log.error("get influenceField error:{}",e.getMessage(),e);
            return RestResponse.fail("查询失败!");
        }
    }
}
